/**
 * 
 */
package org.yelongframework.pdf;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.yelongframework.core.util.function.io.ByteArraySupplier;
import org.yelongframework.core.util.function.io.InputStreamSupplier;

/**
 * PDF绘图数据
 * 
 * @since 1.0.0
 */
public final class PDFDrawImageData {

	/** 图片流供应商 */
	private ByteArraySupplier imageSupplier;

	/** 插入的位置集合 */
	private final List<PDFDrawImagePosition> drawImagePositionList = new ArrayList<>();

	// ==================================================constructor==================================================

	public PDFDrawImageData() {
	}

	/**
	 * @param imageSupplier 图片流供应商
	 */
	public PDFDrawImageData(ByteArraySupplier imageSupplier) {
		setImageSupplier(imageSupplier);
	}

	/**
	 * @param imageSupplier 图片流供应商
	 */
	public PDFDrawImageData(InputStreamSupplier<InputStream> imageSupplier) {
		setImageSupplier(imageSupplier);
	}

	/**
	 * @param imageFilePath 图片文件路径
	 */
	public PDFDrawImageData(String imageFilePath) {
		setImageSupplier(() -> new FileInputStream(imageFilePath));
	}

	/**
	 * @param imageFile 图片文件
	 */
	public PDFDrawImageData(File imageFile) {
		setImageSupplier(() -> new FileInputStream(imageFile));
	}

	// ==================================================get/set==================================================

	/**
	 * @return 图片流供应商
	 */
	public ByteArraySupplier getImageSupplier() {
		return imageSupplier;
	}

	/**
	 * @param imageSupplier 图片流供应商
	 */
	public void setImageSupplier(ByteArraySupplier imageSupplier) {
		this.imageSupplier = imageSupplier;
	}

	/**
	 * @param imageSupplier 图片流供应商
	 */
	public void setImageSupplier(InputStreamSupplier<InputStream> imageSupplier) {
		this.imageSupplier = () -> IOUtils.toByteArray(imageSupplier.get());
	}

	/**
	 * @return 插入的位置集合
	 */
	public List<PDFDrawImagePosition> getDrawImagePositionList() {
		return drawImagePositionList;
	}

	/**
	 * 插入一个位置
	 * 
	 * @param pdfDrawImagePosition 位置信息
	 */
	public void addDrawImagePosition(PDFDrawImagePosition pdfDrawImagePosition) {
		this.drawImagePositionList.add(pdfDrawImagePosition);
	}

}
